package com.example.happiness.controller.admin;

import com.example.happiness.pojo.Employee;
import com.example.happiness.pojo.adminvo.AdminMangeEmployVO;
import com.example.happiness.result.Result;
import com.example.happiness.service.admin.AdminEmployService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "管理员工相关接口")
@Slf4j
@RestController
@RequestMapping("/admin/employ")
public class AdminEmployController {

    @Autowired
    private AdminEmployService adminEmployService;

    @GetMapping("/all")
    @ApiOperation("获取所有员工信息")
    public Result<List<Employee>> getAllEmploy(){
        List<Employee> employees = adminEmployService.getAllEmploy();
        return Result.success(employees);
    }

    @GetMapping("/condition")
    @ApiOperation("获取员工信息和对应的派单信息")
    public Result<List<AdminMangeEmployVO>> getEmployByCondition(){
        List<AdminMangeEmployVO> EmployeeAndOrders = adminEmployService.getEmployAndOrder();
        return Result.success(EmployeeAndOrders);
    }

    @PostMapping("/addEmployee")
    @ApiOperation("添加员工信息")
    public Result addEmployee(@RequestBody Employee employee){
        return adminEmployService.addEmployee(employee);
    }

    @PostMapping("/upEmployee")
    @ApiOperation("修改员工信息")
    public Result upEmployee(@RequestBody Employee employee){
        adminEmployService.upEmployee(employee);
        return Result.success();
    }

    @DeleteMapping("/delEmployee")
    @ApiOperation("删除员工信息")
    public Result delEmployee(String employid){
        adminEmployService.delEmployee(employid);
        return Result.success();
    }
}
